const menu = {
    home : {
        title : '首页',
        route : '/'
    },
    curriculum : {
        title : '课程',
        route : '/curriculum/list',
        subs : {
            list: {
                title : '所有课程',
                route : '/curriculum/list'
            },
            new: {
                title : '创建课程',
                route : '/curriculum/new'
            },
            create_chapter : {
                title : '创建章节',
                route : '/curriculum/create_chapter'
            },
            create_hour : {
                title : '创建课时',
                route : '/curriculum/create_hour'
            },
            test : {
                title : '测试测试',
                route : '/curriculum/test'
            }
        }
    },
    student : {
        title : '学生',
        route : '/student/list',
        subs : {
            list: {
                title: '所有学生',
                route: '/student/list'
            },
            new: {
                title: '添加学生',
                route: '/student/new'
            }
        }
    }
};

const router = [
    {
        path : '/',
        meta : menu.home,
        component : require('../pages/Console/Index.vue')
    },
    {
        path : '/curriculum/new',
        meta : menu.curriculum.subs.new,
        component : require('../pages/Curriculum/Edit.vue')
    },
    {
        path : '/curriculum/list',
        meta : menu.curriculum.subs.list,
        component : require('../pages/Curriculum/List.vue')
    },
    {
        path : '/curriculum/create_chapter',
        meta : menu.curriculum.subs.create_chapter,
        component : require('../pages/Curriculum/CreateChapter.vue')
    },
    {
        path : '/curriculum/create_hour',
        meta : menu.curriculum.subs.create_hour,
        component : require('../pages/Curriculum/CreateHour.vue')
    },
    {
        path : '/curriculum/test',
        meta : menu.curriculum.subs.test,
        component : require('../pages/Curriculum/test.vue')
    },
    {
        path : '/student/new',
        meta : menu.student.subs.new,
        component : require('../pages/Student/Edit.vue')
    },
    {
        path : '/student/list',
        meta : menu.student.subs.list,
        component : require('../pages/Student/List.vue')
    }
];

for(let i in menu){
    if('subs' in menu[i]){
        for(let val in menu[i].subs){
            menu[i].subs[val].parent = menu[i];
        }
    }
}

const beforeRouteEnter  = function(to, from, next) {
    for(let i in menu){
        menu[i].active = false;
        if('subs' in menu[i]){
            for(let val in menu[i].subs){
                menu[i].subs[val].active = false;
            }
        }
    }
    to.meta.active = true;
    if('parent' in to.meta)
        to.meta.parent.active = true;
    next();
};


for(let item of router){
    item.beforeEnter = beforeRouteEnter;
}

export default {
    router : router,
    menu : menu
};